﻿using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

using IfSoft.OA.Entities;

namespace IfSoft.OA.DataAccess
{
    public class OADBContext : DbContext
    {
        static OADBContext()
        {
            Database.SetInitializer<OADBContext>(null);
        }

        public OADBContext()
        {
            base.Configuration.LazyLoadingEnabled = false;
            base.Configuration.ProxyCreationEnabled = false;
        }

        public OADBContext(string connectionString)
            : base(connectionString)
        {
            base.Configuration.LazyLoadingEnabled = false;
            base.Configuration.ProxyCreationEnabled = false;
        }


        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Attatchment> Attachments { get; set; }

        public DbSet<BankBill> BankBills { get; set; }
        public DbSet<BankBillDetail> BankBillDetails { get; set; }
        
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

            modelBuilder.Configurations.Add(new UserMap());
            modelBuilder.Configurations.Add(new RoleMap());
            modelBuilder.Configurations.Add(new BankBillMap());
            modelBuilder.Configurations.Add(new BankBillDetailMap());
        }

    }
}

